package com.ruoyi.framework.shiro.util;

import com.alibaba.druid.filter.config.ConfigTools;

/**
 * 描述 使用com.alibaba.druid.filter.config.ConfigTools进行加密和解密工具类
 *
 */
public class RsaEncryptAndDecodeUtil {
    /**
     * 公钥(用于解密)
     */
    private static final String RSA_PUBLIC_KEY = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAJ2+ov1PaeoAqp6bTqOw61RrOH+NBt+CPS4vrQ03TMXmkf4g5tcYtZZ8KMprNzQFpqAQWY6PIYdRpl5R8YzsRdECAwEAAQ==";

    /**
     * 私钥加密(用于加密)
     */
    private static final String RSA_PRIVATE_KEY = "MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAnb6i/U9p6gCqnptOo7DrVGs4f40G34I9Li+tDTdMxeaR/iDm1xi1lnwoyms3NAWmoBBZjo8hh1GmXlHxjOxF0QIDAQABAkEAm3GRYbcQ8tPHTlZS7wFXVS/3U9Hf9P59VXcLu5tD3zrar4DwVPoVp/16UAq3xm/u1g9ry4IHxZ9z55n9tXIThQIhAPhIFgPIti5oiDREMdRxQheE1i9Mc+DQhgrwwbLw2qwzAiEAoqYGguXAiDnH8gt0Xfi+N+jzWj0rATIwtAlPWzxsAesCIF0OD4o9iOKd9Sa5xH9eL6pG9Evn+KpzHTougDrEAQF3AiAHbEpZyQCLdw+gBVPPQh30UUZh9O60hETiwpYDlPNc9wIgRxyTri0lNppZV4KaZ6Pbro/hknZGlpI4W/63lAXK1So=";


    public static void main(String[] args) {
        String miwen = encrypt("afd123@pyui#");
        System.out.println("密文=====>" + miwen);
        String mingwen = decrypt(miwen);
        System.out.println("名文=====>" + mingwen);
    }

    /**
     * 描述 私钥加密
     *
     */
    public static String encrypt(String strMing) {
        try {
            return ConfigTools.encrypt(RSA_PRIVATE_KEY, strMing);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;

    }

    /**
     * 描述 公钥解密
     *
     */
    public static String decrypt(String strMi) {
        try {
            return ConfigTools.decrypt(RSA_PUBLIC_KEY, strMi);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }


}